package com.java.yz.day13.ketang;

import java.io.*;

/*
InputStreamWriter读数据方法
    public int read()
    public int read(char[] cbuf)

 */
public class InputStreamReaderDemo2 {
    public static void main(String[] args) {
        InputStreamReader isr = null;
        try {
            //isr = new InputStreamReader(new FileInputStream("src/com/java/yz/day13/ketang/e.txt"));

            //第二种构造方法传入InputStream的一个具体实现子类并且加上一个编码表
            isr = new InputStreamReader(new FileInputStream("src/com/java/yz/day13/ketang/d.txt"),"GBK");
            //public int read() 一下只能读取一个字符
            //System.out.println(isr.read());

            //public int read(char[] cbuf)
            //读取多个字符
            char[] chars = new char[1024];
            int i = 0 ;
            while ((i=isr.read(chars))!=-1){
                String s = new String(chars,0,i);
                System.out.println(s);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (isr != null){
                try {
                    isr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
